//
//  ViewController.swift
//  77Club
//
//  Created by Apple on 2024/8/26.
//

import UIKit

class ViewController: ClubBaseViewController {

    private let bgImageView         = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).end()
    private let bottomView         = c_make_ex(UIView.self)
        .bgColor("#F7F8FA").end()
    private let logoImageView         = c_make_ex(UIImageView.self)
        .image("AppIcon").corner(8.0.Scale).mode(.scaleAspectFill).end()
    private let logoLabel         = c_make_ex(UILabel.self)
        .font(16.font_semiBold).alignment(.center).color(.black).end()
    
    var completion: (() -> Void)?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        loadData()
        
        view.subviews{
            bgImageView
            bottomView
            logoImageView
            logoLabel
        }
        
        bgImageView.leading(0).trailing(0).top(0).bottom(.tabBar_height + 70)
        bottomView.leading(0).trailing(0).bottom(0).height(.tabBar_height + 70)
        logoImageView.size(38.0.Scale).bottom(.tabBar_height).centerHorizontally()
        logoLabel.centerHorizontally()
        logoLabel.Top == logoImageView.Bottom + 8.0.Scale
        logoLabel.text = Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String
        
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            
            self.completion?()
        }
    }

    private func loadData(){
        
        Task{
            
            Task {
                let res = await network.request(.getLaunchScreen,type: ClubLaunchModel.self)
                if res.isSuccess, let model = res.model {
                    
                    self.bgImageView.loadImage(url: model.image)
                }
            }
        }
    }
}

